/**
 * Created by kim on 2015/10/9.
 */

(function ($, hb) {
  'use strict';
  var def = {
    lines: 8,
    length: 0,
    width: 4,
    radius: 4,
    corners: 1,
    rotate: 0,
    direction: 1,
    color: '#fff',
    speed: 1,
    trail: 70,
    shadow: false,
    hwaccel: false,
    className: 'spinner',
    zIndex: 2e9,
    top: '50%',
    left: '20%'
  };

  var spin = {
    show: function (target) {
      var $target = $(target);
      if ($target.length > 0) {
        var spin = $target.data('spin');
        if (!spin) {
          var Spinner = require('spin');
          spin = new Spinner(def).spin($target.get(0));
          $target.data('spin', spin);
        } else {
          spin.spin($target.get(0));
        }
      }
    },

    stop: function (target) {
      var $target = $(target);
      if ($target.length > 0) {
        var spinner = $target.data('spin');
        if (spinner) {
          spinner.stop();
        }
      }
    }
  };
  hb.spin = spin;
})
(jQuery, HB);